import { getCompanyPatentPaymentList } from '@/util/api/patent'
export default {
  data() {
    return {
      labelList: [
        { id: '',label: '全部' },
        { id: '1',label: '一个月' },
        { id: '2',label: '两个月' }
      ],
      currentLabel: 0,
      all: '',
      isAllSelected: false, // 是否全部被选中
      checkedList :[], // 默认选中的值
      
      form:{
        pageNo: 1,
        pageSize: 10,
        patentType: '',
        month: '',
        companyId: '',
        name: ''
      },
      companyName: '',
      patentList: [],
      total: '',
      showText: false,
      nums: '' // 选中的专利号
    }
  },
  onLoad(e) {
    if(e.id) {
      this.form.companyId = e.id
    }
    this.form.name = e.name
    this.companyName = e.name

    this.getList()
  },
  // 上拉加载更多
    onReachBottom() {
      // 加载下一页
      this.form.pageNo = this.form.pageNo + 1;
      if (this.total > this.patentList.length) {
        this.getList();
      } else {
        this.showText = true;
      }
    },
  methods: {
    changeLabel(item,index) {
      this.currentLabel = index
      this.form.month = item.id
      this.form.pageNo = 1
      this.patentList = []
      this.getList()
    },
    /** 全选复选框的checkbox-group  changge事件 */
    // checkboxAllChange: function (e){
    //   console.log(e,'全选事件')
    //   if(e.detail.value.length>0){
    //     this.isAllSelected = true;	
    //   }else{
    //     // 否则全选状态为false
    //     this.isAllSelected = false;
    //   }
    // },
    /** 复选框组合的checkbox-group  changge事件*/
    checkboxChange: function (e) {
      var list = this.patentList; // 有复选框的数组集合

      this.checkedList = e.detail.value; // 选中的数组集合 
      this.nums = this.checkedList.join(',')
      // 对有复选框的数组集合进行遍历
        for (var i = 0, lenI = list.length; i < lenI; ++i) {
          const item = list[i]
          // 如果当前选中的数组包含复选框数组中的某个元素，则设置为选中状态
          if(this.checkedList.includes(item.announcementNumber)){
            this.$set(item,'checked',true)
          }else{
            // 否则设置为补选中状态
            this.$set(item,'checked',false)
          }
        }
    },
    // 列表数据
    getList() {
      for (const key in this.form) {
        if (!String(this.form[key]).length) delete this.form[key];
      }
      getCompanyPatentPaymentList(this.form).then(res=>{
        if(res.code === 200) {
          let { total, records } = res.result
          this.total = total
          this.patentList.push(...records)
        } else {
          uni.showToast({
            title: res.message,
            duration: 2000,
            icon: "none"
          });
        }
      })
    },
    // 专利详情
    toPatentDetail(item) {
      uni.navigateTo({
        url: `/pages/patent/detail/Index?id=${item.announcementNumber}&companyId=${this.form.companyId}`
      })
    },
    // 专利缴费
    toPayment() {
      let token = this.$getToken();
      if (!token) {
        uni.showToast({
          title: "您还没有登录，请登录后操作",
          duration: 2000,
          icon: "none",
        })
        setTimeout(()=>{    
          uni.setStorageSync("pageUrl", window.location.href);   
          uni.navigateTo({
            url: "/pages/login/index",
          })
        },2000)  
      } else if(this.nums){
        uni.navigateTo({
          url: `/pages/patent/payment/Index?nums=${this.nums}`
        })
      } else {
        uni.showToast({
          title: "请先选择需要缴费的专利！",
          duration: 2000,
          icon: "none"
        });
      }
    }
  }
}